package com.alibaba.citrus.cr.unified.inventory.repository.impl;

import com.alibaba.citrus.cr.unified.inventory.repository.ConsignmentOrderLineRepository;
import com.alibaba.citrus.cr.unified.inventory.utils.ConsignmentConverter;
import com.epoch.app.crunifiedinventory.consignmentorderline.dto.CreateConsignmentOrderLineResponse;
import com.epoch.app.crunifiedinventory.consignmentorderline.model.ConsignmentOrderLine;
import com.epoch.app.crunifiedinventory.consignmentorderline.service.ConsignmentOrderLineService;
import com.epoch.app.crunifiedinventory.sdo.ConsignmentOrderLineSDO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ConsignmentOrderLineRepositoryImpl implements ConsignmentOrderLineRepository {

    @Resource
    private ConsignmentOrderLineService consignmentOrderLineService;

    @Override
    public String create(ConsignmentOrderLineSDO consignmentOrderLineSDO) {
        ConsignmentOrderLine consignmentOrderLine = ConsignmentConverter.converterOrderLine(consignmentOrderLineSDO);
        CreateConsignmentOrderLineResponse consignmentOrderLine1 = consignmentOrderLineService.createConsignmentOrderLine(consignmentOrderLine);
        return consignmentOrderLine1.getLastInsertId();
    }

    @Override
    public Boolean delete(ConsignmentOrderLineSDO consignmentOrderLineSDO) {
        ConsignmentOrderLine consignmentOrderLine = ConsignmentConverter.converterOrderLine(consignmentOrderLineSDO);
        consignmentOrderLineService.updateConsignmentOrderLine(consignmentOrderLine);
        return true;
    }

    @Override
    public Boolean update(ConsignmentOrderLineSDO consignmentOrderLineSDO) {
        ConsignmentOrderLine consignmentOrderLine = ConsignmentConverter.converterOrderLine(consignmentOrderLineSDO);
        consignmentOrderLineService.updateConsignmentOrderLine(consignmentOrderLine);
        return true;
    }
}
